﻿namespace Sustainalytics.Portfolios.Servive.Tests
{
    using System;
    using System.Net;
    using System.Net.Http;
    using System.Net.Http.Formatting;
    using System.Threading.Tasks;
    using System.Web;
    using System.Web.Http;
    using System.Web.Http.Controllers;
    using System.Web.Http.Dispatcher;

    using FakeItEasy;

    using Microsoft.Owin.Testing;

    using Owin;

    using Sustainalytics.Claims;
    using Sustainalytics.OAuth.Services.Common;
    using Sustainalytics.Portfolios.BL;
    using Sustainalytics.Portfolios.BL.Exceptions;
    using Sustainalytics.Portfolios.Service;
    using Sustainalytics.Portfolios.Service.Controllers;
    using Sustainalytics.Portfolios.Service.Infrastructure;
    using Sustainalytics.Portfolios.Service.Models;
    using Sustainalytics.Portfolios.Service.Utility;


    using Xunit;

    public static class HttpClientExtensions
    {
        public static Task<HttpResponseMessage> PatchAsJsonAsync<T>(this HttpClient client, string requestUri, T value)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (requestUri == null)
            {
                throw new ArgumentNullException("requestUri");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var content = new ObjectContent<T>(value, new JsonMediaTypeFormatter());
            var request = new HttpRequestMessage(new HttpMethod("PATCH"), requestUri) { Content = content };

            return client.SendAsync(request);
        }
    }
}